﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <script src="~/js/frame.js"></script>
    <style>
        .RoleCheckBoxContainer {
            margin: 5px;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <form id="form">
            <div class="panel-group" id="baseinfo" aria-multiselectable="true">
                <div class="panel panel-default">
                    <div class="panel-heading" id="basehead">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#baseinfo" href="#basecontent">
                                基本信息
                            </a>
                        </h4>
                    </div>
                    <div id="basecontent" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <div class="formrow">
                                <div class="col-xs-12">
                                    <div class="formtitle required">所属部门</div>
                                    <div class="formcontent">
                                        <cloud-tree id="OUGuid" url="tree" control-type="selectou" select-type="single" readonly></cloud-tree>
                                    </div>
                                </div>
                            </div>
                            <div class="formrow">
                                <div class="col-xs-6">
                                    <div class="formtitle required">登录名</div>
                                    <div class="formcontent">
                                        <input name="LoginID" type="text" class="form-control required" placeholder="" disabled>
                                    </div>
                                </div>
                                <div class="col-xs-6">
                                    <div class="formtitle required">人员姓名</div>
                                    <div class="formcontent">
                                        <input name="DisplayName" type="text" class="form-control required" disabled>
                                    </div>
                                </div>
                            </div>
                            <div class="formrow">
                                <div class="col-xs-6">
                                    <div class="formtitle">性别</div>
                                    <div class="formcontent">
                                        <div class="formcontent">
                                            <label class="radio-inline">
                                                <input type="radio" name="Sex" checked value="100" disabled>男
                                            </label>
                                            <label class="radio-inline">
                                                <input type="radio" name="Sex" value="200" disabled>女
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xs-6">
                                    <div class="formtitle">手机号码</div>
                                    <div class="formcontent">
                                        <input name="Mobile" type="text" class="form-control" disabled>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel-group" id="roleinfo" aria-multiselectable="true">
                <div class="panel panel-default">
                    <div class="panel-heading" id="orgrighthead">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#roleinfo" href="#rolecontent">
                                角色设置
                            </a>
                        </h4>
                    </div>
                    <div id="rolecontent" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <div style="width:100%;display:flex;flex-direction:row;flex-wrap:wrap" id="RoleContainer">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div style="display:none">
                <input name="UserGuid" type="text" class="form-control" placeholder="">
            </div>
            <div class="row formbtnop">
                <button class="btn btn-primary cloudbtn" type="button" onclick="Save()">保 存</button>
                <button class="btn cloudbtn" type="button" onclick="Close()">关 闭</button>
            </div>
        </form>
    </div>
    <script>
        var formvalidator = $("#form").validate();
        $(function () {
            LoadDetail();
        })
        function LoadDetail() {
            var param = { "UserGuid": GetUrlParam("userguid") }
            CloudPost(param, "opdetail", function (res) {
                if (res.code == 0) {
                    $("#form").SetForm(res.data);
                    $("#OUGuid").attr("selectvalue", res.data.OUGuid);
                    RenderTree();
                    var RowData = res.data;
                    CloudPost({}, getRootPath() + "frame/org/role/oplistall", function (RoleRes) {
                        var RoleHtml = "";
                        $(RoleRes.data).each(function (index, Role) {
                            if (RowData.RoleGuidList.indexOf(Role.RoleGuid) > -1) {
                                RoleHtml += "<div class='RoleCheckBoxContainer'><input type='checkbox' class='RoleCheckBox' checked UserGuid='" + RowData.UserGuid + "' RoleGuid='" + Role.RoleGuid + "' id=" + Role.RoleGuid + "><label for=" + Role.RoleGuid + ">" + Role.RoleName + "</label></div>";
                            } else {
                                RoleHtml += "<div class='RoleCheckBoxContainer'><input type='checkbox' class='RoleCheckBox' UserGuid='" + RowData.UserGuid + "' RoleGuid='" + Role.RoleGuid + "'  id=" + Role.RoleGuid + "><label for=" + Role.RoleGuid + ">" + Role.RoleName + "</label></div>";
                            }
                        })
                        $("#RoleContainer").html(RoleHtml)
                    })
                }
            })
        }

        function Save() {
            var Result = [];
            $(".RoleCheckBox").each(function () {
                if ($(this).prop('checked')) {
                    Result.push({ "UserGuid": $(this).attr("UserGuid"), "RoleGuid": $(this).attr("RoleGuid"), "IsCheck": true });
                } else {
                    Result.push({ "UserGuid": $(this).attr("UserGuid"), "RoleGuid": $(this).attr("RoleGuid"), "IsCheck": false });
                }
            })
            CloudPost({ "UserRoleRelationStr": JSON.stringify(Result) }, getRootPath() + "frame/org/userrole/batchUpdateUserRole", function (res) {
                if (res.code == 0) {
                    OpenSuccess("保存成功", Close)
                }
            })
        }
        function Close() {
            CloseDialog();
        }
    </script>
</body>
</html>
